#!/bin/sh

compDvh()
{
# plan directory
cpwd=`pwd`
d=$1

if [ ! -d "${d}/a" ]; then
 echo "anastructure directory not found"
 exit 1
fi

if [ ! -d "${d}/dvh" ]; then
 echo "dvh directory not found => creating a dvh directory"
 mkdir dvh
fi

# list of all anastructs
echo "Creating list of anastructures"
anaList=`for i in \`ls ${d}/a\`; do echo "${i}"; done`

# go in dvh directory
cd ${d}/dvh

for i in ${anaList[@]}; do
  echo "Creating dvh data for anastruct ${i}"
  if [ ! -e "${i}.pts" ]; then
    fill_anastruct_with_points -a ../a/${i} -p ./${i}.pts -c 10000
  fi
  compute_dvh -g ../sum -p ./${i}.pts -d ./${i}.ddvh
  accumulate_dvh ./${i}.ddvh ./${i}.cdvh
  make_dvh_bars ./${i}.ddvh ./${i}.ddvh.bar
done

cd ${cpwd}
}
